using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Sudoku.Menu
{
	public class BlinkString : ExtendedGameComponent
	{
		private String mex;
		private float delay;
		private float nextBlink;
		private float duration;
		private Vector2 pos;
		private Vector2 shadowPos;
		private Color color;
		private SpriteFont font;

		private bool draw;

		public BlinkString(Game game, SpriteFont font, String mex, Vector2 pos, Color color, float delay, float blinkDuration) 
			: base(game)
		{
			this.font = font;
			this.mex = mex;
			this.pos = pos;
			this.color = color;
			this.delay = delay;
			this.duration = blinkDuration;
		}

		public override void Initialize()
		{
			draw = true;
			nextBlink = delay;
			shadowPos = new Vector2(pos.X + 1.0f, pos.Y + 1.0f);
			base.Initialize();
		}

		public override void Update(GameTime gameTime)
		{
			if( gameTime.TotalGameTime.TotalMilliseconds > nextBlink)	//Blink time!
			{
				draw = !draw;
				nextBlink = (draw) ?
					delay + (float)gameTime.TotalGameTime.TotalMilliseconds :
					duration + (float)gameTime.TotalGameTime.TotalMilliseconds;
			}
			base.Update(gameTime);
		}

		public override void Draw(GameTime gameTime)
		{
			if (draw)
			{
				spriteBatch.Begin();

				spriteBatch.DrawString(font, mex, shadowPos, Color.Black);
				spriteBatch.DrawString(font, mex, pos, color);
				
				spriteBatch.End();
			}
			base.Draw(gameTime);
		}
	}
}
